package _18_剑指OfferII;

import _18_剑指OfferII.datastrcute.TreeNode;

public class _052_剑指OfferII展平二叉搜索树 {

    private TreeNode resNode;

    public TreeNode increasingBST(TreeNode root) {
        TreeNode dummy = new TreeNode(-1);
        resNode = dummy;
        dfs(root);
        return dummy.right;
    }

    public void dfs(TreeNode root) {
        if (root == null) return;
        dfs(root.left);
        resNode.right = root;
        root.left = null;
        resNode = root;
        dfs(root.right);
    }

}
